package com.unhz.generator.utils;

import com.alibaba.fastjson.JSONObject;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;



/**
 *	短信工具类
 * @author liujl
 *
 */
public class MsgUtil {
	private static final MsgUtil MsgUtil = null;


	//密码
	private String PASSWORF="QC*pHnwf ";
	/**
	 * 账号：6038  密码：QC*pHnwf   网址：www2.yunqixun.cn
	 * appkey：ApiKey：50c77ce34e303c3232e75d24c94c6f82  sign：Sign：YjY4OTM2YmVhZDZjYzVkN2FiZGI3NzM3NjllMGZiMDg=
	 *
	 * 发送短信接口
	 * @param mobile	手机号
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public  Map sendMsg(String mobile, HttpServletRequest   request) throws UnsupportedEncodingException {
		//这里调用你生成的验证码方法
		//企业id
		String userid="1234";
		String str = "";
		str += (int)(Math.random()*9+1);
		for(int i = 0; i < 5; i++){
			str += (int)(Math.random()*10);
		}
		int num = Integer.parseInt(str);
		String k=String.valueOf(num);
		System.out.println(k);
		HashMap map=new HashMap();
//		map.put("kkk", k);


		String url = "http://202.91.244.252:30001/yqx/v1/sms/single_send";
		JSONObject json=new JSONObject();
		json.put("account",6038);
		json.put("mobile",mobile);
		json.put("sign","YjY4OTM2YmVhZDZjYzVkN2FiZGI3NzM3NjllMGZiMDg=");
		json.put("text","【云企讯】您的验证码是 "+k);
		System.out.println(json.get("text"));

		String str1 = HttpClient.sendPost(url,json.toJSONString());
		String j1=new String(str1.getBytes("GBK"),"UTF-8");
		System.out.println(j1);
		Map smsInfo=new HashMap();
		smsInfo.put("smsCode",k);
		smsInfo.put("expries",String.valueOf (new Date().getTime()) + 1*60*1000);
		SmsUtil.addSmsCode(mobile, smsInfo);
		return map;
	}
}


